/*
 * @Author: LC
 * @Date: 2021-10-08
 * @Description:

 */
'use strict';

export default app => {
  const { STRING, INTEGER } = app.Sequelize;

  // 菜单表
  const Menu = app.model.define('Menu', {
    id: {
      primaryKey: true,
      type: INTEGER,
      autoIncrement: true,
      comment: '菜单id',
    },
    name: {
      type: STRING(50),
      defaultValue: null,
      comment: '菜单名称',
    },

    path: {
      type: STRING(300),
      defaultValue: null,
      comment: '菜单路径',
    },
    icon: {
      type: STRING(300),
      defaultValue: null,
      comment: '菜单图标',
    },
    status: {
      type: INTEGER,
      defaultValue: 1,
      comment: '菜单状态',
    },
    sort: {
      type: INTEGER,
      defaultValue: 0,
      comment: '菜单排序',
    },
    parentId: {
      type: INTEGER,
      defaultValue: 0,
      comment: '父级菜单id',
    },
    type: {
      type: INTEGER,
      defaultValue: 0,
      comment: '菜单类型',
    },
  },
  {
    tableName: 'menu',
    comment: '菜单表',
    timestamps: false,
  });
  // 菜单表关联角色表
  Menu.associate = function() {
    app.model.Menu.belongsTo(app.model.Role, {
      foreignKey: 'roleId',
      targetKey: 'id',
      as: 'role',
    });
  };


  return Menu;


};

